
package com.assistant.core.modules.sys.app.menu;

import com.assistant.core.modules.sys.app.menu.cmd.MenuInsertCmd;
import com.assistant.core.modules.sys.app.menu.cmd.MenuUpdateCmd;
import com.assistant.core.modules.sys.domain.menu.Menu;
import com.assistant.core.modules.sys.domain.menu.gateway.MenuGateway;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuService {

    @Autowired
    private MenuGateway gateway;

    public Menu get(Long id) {
        return gateway.getById(id);
    }

    public List<Menu> list() {
        return gateway.findAll();
    }

    public void insert(MenuInsertCmd cmd) {
        Menu menu = new Menu();
        BeanUtils.copyProperties(cmd, menu);
        gateway.save(menu);
    }

    public void update(MenuUpdateCmd cmd) {
        Menu menu = gateway.getById(cmd.getId());
        BeanUtils.copyProperties(cmd, menu);
        gateway.save(menu);
    }

    public void delete(Long id) {
        gateway.deleteById(id);
    }
}

